package com.supervision.manage.mapper.sqlprovider

import com.supervision.domain.bean.po.CourtOrgSearchPO
import org.apache.commons.lang3.StringUtils
import java.lang.StringBuilder

class CourtOrgSqlProvider {

    fun getCourtOrgList(param: HashMap<String, Any>): String {
        val po = param["po"] as CourtOrgSearchPO
        val limitSql = param["limitSql"] as String
        val sql = StringBuilder()
        if (limitSql.isEmpty()) {
            sql.append(" select count(*) ")
        } else {
            sql.append(" select * ")
        }
        sql.append(" from court_org ")
        sql.append(" where weight >= 0 ")
        if (po.name.isNotEmpty()) {
            sql.append(" and name like concat('%', #{po.name},'%') ")
        }
        sql.append(" order by id desc ")

        return sql.toString() + StringUtils.defaultString(limitSql, StringUtils.EMPTY)
    }
}